home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
toswinsc.zoo
/
winops.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-27
|
17KB
|
769 lines
/*
* Copyright 1992 Eric R. Smith. All rights reserved.
* Redistribution is permitted only if the distribution
* is not for profit, and only if all documentation
* (including, in particular, the file "copying")
* is included in the distribution in unmodified form.
* THIS PROGRAM COMES WITH ABSOLUTELY NO WARRANTY, NOT
* EVEN THE IMPLIED WARRANTIES OF MERCHANTIBILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. USE AT YOUR OWN
* RISK.
*/
#include "xgem.h"
#include <osbind.h>
#include <mintbind.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include "toswin.h"
#include "twdefs.h"
#include "twproto.h"
#define FLASHTIME 30
/* external flag: set to indicate the flag for opening a
* "global" file (if we need to) when we're starting up
*/
extern int global_flag;
/* file descriptors that have kids attached to them */
long fd_mask = 0L;
/* file descriptor of TOSRUN */
extern int trun_fd;
static void write_win __PROTO((TEXTWIN *, char *, int));
/*
* get a file name using the file selector.
* "title" is the file selector box title
* "path" is where to look for the file;
* "default_name" is a default name for the file;
* the final name selected is returned in "name"
*/
int
getfilename(title, name, path, default_name)
char *title;
char *name;
char *path, *default_name;
{
extern char *rindex();
char *s;
int fresult, fbutton;
extern int gl_ap_version;
if (path[0] == 0) {
path[0] = Dgetdrv() + 'A';
path[1] = ':';
(void)Dgetpath(&path[2], 0);
strcat(path, "\\");
}
for (s = path; *s; s++) {
if (*s == '*') goto nowildcard;
}
strcpy(s, "*.*");
nowildcard:
if (gl_ap_version >= 0x140)
fresult = fsel_exinput(path, default_name, &fbutton, title);
else
fresult = fsel_input(path, default_name, &fbutton);
if (fresult <= 0 || fbutton != 1 || !default_name[0])
return FAIL;
s = rindex(path, '\\');
if (!s)
s = &path[2];
else
s++;
*s = 0;
strcpy(name, path);
strcat(name, default_name);
return OK;
}
/*
* if the program named by "fname" is a .TTP one, prompt the
* user for arguments and copy them into "argstr"; otherwise
* copy in a null command line. Return FAIL if the user
* cancelled the request.
*/
int
getargs(fname, argstr)
char *fname, *argstr;
{
char *lastdot = 0;
int i, x, y, w, h;
TEDINFO *ted;
OBJECT *argdial;
char *inp;
*argstr = 0;
while (*fname) {
if (*fname == '.')
lastdot = fname;
else if (*fname == '\\')
lastdot = 0;
fname++;
}
if (lastdot && !strcmp(lastdot, ".TTP")) {
rsrc_gaddr(0, ARGDIAL, &argdial);
ted = (TEDINFO *)argdial[ARGSTR].ob_spec;
inp = (char *)ted->te_ptext;
*inp = 0;
form_center(argdial, &x, &y, &w, &h);
wind_update(1);
form_dial(FMD_START, 0, 0, 32, 32, x, y, w, h);
if (win_flourishes)
form_dial(FMD_GROW, 0, 0, 32, 32, x, y, w, h);
objc_draw(argdial, 0, 2, x, y, w, h);
i = form_do(argdial, ARGSTR);
if (win_flourishes)
form_dial(FMD_SHRINK, 0, 0, 32, 32, x, y, w, h);
form_dial(FMD_FINISH, 0, 0, 32, 32, x, y, w, h);
objc_change(argdial, i, 0, x, y, w, h, NORMAL, 0);
wind_update(0);
if (i == ARGCAN) return FAIL;
strcpy(argstr, inp);
}
return OK;
}
char progpath[128];
char dfltprog[128];
int
getprogname(name)
char *name;
{
return getfilename(Strng(EXECPRG), name, progpath, dfltprog);
}
/*
* typeit: type the user's input into a window. Note that this routine is
* called when doing a 'paste' operation, so we must watch out for possible
* deadlock conditions
*/
#define READBUFSIZ 256
static char buf[READBUFSIZ];
int
typeit(w, code, shift)
WINDOW *w;
int code, shift;
{
TEXTWIN *t = w->extra;
long offset, height;
long c = (code & 0x00ff) | (((long)code & 0x0000ff00) << 8L) |
((long)shift << 24L);
long r;
if (t->miny) {
offset = t->miny * t->cheight;
if (offset > t->offy) {
/* we were looking at scroll back */
/* now move so the cursor is visible */
height = t->cheight * t->maxy - w->wi_h;
if (height <= 0)
offset = 0;
else {
offset = 1000L * t->cy * t->cheight/height;
if (offset > 1000L) offset = 1000L;
}
(*w->vslid)(w, offset);
}
}
if (t->fd) {
r = Foutstat(t->fd);
if (r <= 0) {
r = Fread(t->fd, (long)READBUFSIZ, buf);
if (r > 0) {
write_win(t, buf, (int)r);
}
(void)Fselect(500,0L,0L,0L);
r = Foutstat(t->fd);
}
if (r > 0) {
(void)Fputchar(t->fd, c, 0);
return 1;
}
}
return 0;
}
void (*oldtopped)(), (*oldclosed)();
extern MENU *sysbar;
extern int appl_menus, sys_menu;
void
top_menu(v, f)
WINDOW *v;
void (*f)();
{
ENTRY *e;
TEXTWIN *t = v->extra;
TEXTWIN *oldt;
int enable = (v->wtype == TEXT_WIN);
if (gl_topwin && gl_topwin->wtype == TEXT_WIN &&
gl_topwin->extra != t)
oldt = gl_topwin->extra;
else
oldt = 0;
for (e = windowmenu->contents; e; e = e->next) {
if (e->entry[0] != '-')
if (enable)
enable_entry(windowmenu, e);
else
disable_entry(windowmenu, e);
}
for (e = gadgmenu->contents; e; e = e->next) {
if (e->entry[0] != '-')
if (enable)
enable_entry(gadgmenu, e);
else
disable_entry(gadgmenu, e);
}
enable_entry(filemenu, closeentry);
#ifdef GLOBL_APPL_MENUS
if (v->menu && appl_menus) {
show_menu(v->menu);
sys_menu = 0;
} else if (!sys_menu) {
show_menu(sysbar);
sys_menu = 1;
}
#endif
if (enable)
curs_off(t);
if (oldt) {
/* change the cursor states, maybe */
curs_off(oldt);
}
(*f)(v);
focuswin = gl_topwin;
if (enable) {
curs_on(t);
refresh_textwin(t);
}
if (oldt) {
curs_on(oldt);
refresh_textwin(oldt);
}
}
static void
top_text(v)
WINDOW *v;
{
top_menu(v, oldtopped);
}
static void
desk_menu(v)
WINDOW *v;
{
ENTRY *e;
(*oldclosed)(v);
if (v->menu)
unloadmenu(v->menu);
if (!gl_topwin) {
for (e = windowmenu->contents; e; e = e->next) {
if (e->entry[0] != '-')
disable_entry(windowmenu, e);
}
for (e = gadgmenu->contents; e; e = e->next) {
if (e->entry[0] != '-')
disable_entry(gadgmenu, e);
}
disable_entry(filemenu, closeentry);
#ifdef GLOBAL_APPL_MENUS
if (!sys_menu) {
show_menu(sysbar);
sys_menu = 1;
}
#endif
}
}
/*
* set up a new text window with a process running in it
* "progname" is the program's name;
* "progargs" are the arguments for it;
* "progdir" is the directory to change to;
* "x" and "y" give where the window is to be opened
* "rows" and "cols" are the number of rows and columns for it,
* respectively;
* "scroll" are the number of lines of scrollback to be
* alloted for the window
*
* NOTE: the window is *not* actually opened here; it's the
* caller's responsibility to do that.
*/
TEXTWIN *
newproc(progname, progargs, progdir, x, y, cols, rows, scroll, kind,
font, points)
char *progname, *progargs, *progdir;
int x, y, cols, rows, kind, scroll, font, points;
{
extern void vt52_putch();
extern long termfunc; /* set in main.c */
TEXTWIN *t;
int i, ourfd, kidfd;
#ifdef OLD_WAY
long oldblock;
#else
long r;
#endif
static char termname[64];
static char argbuf[128];
struct winsize tw;
char *p, *arg, c;
char *newenv = 0;
int oldfont, oldheight;
/* copy over the args */
p = argbuf+1;
arg = progargs;
for (i = 0; i < 125; i++) {
c = *arg++;
if (!c || c == '\r' || c == '\n') break;
*p++ = c;
}
*p = 0;
argbuf[0] = i;
oldfont = default_font;
oldheight = default_height;
default_font = font;
default_height = points;
t = create_textwin(progname, x, y, cols, rows, scroll, kind);
default_font = oldfont;
default_height = oldheight;
if (!t) {
form_alert(1, AlertStrng(NOWINS));
return 0;
}
t->output = vt52_putch;
t->prog = strdup(progname);
t->cmdlin = strdup(progargs);
t->progdir = strdup(progdir);
t->win->menu = loadmenu(progname);
if (t->win->menu) {
t->win->infostr = strdup(menustr(t->win->menu));